package org.example;

import javax.swing.text.SimpleAttributeSet;
import javax.swing.text.StyleConstants;
import java.awt.*;

public class ColoStyles {
    private static SimpleAttributeSet redAttr;
    private static SimpleAttributeSet blackAttr;
    private static SimpleAttributeSet greenAttr;
    private static SimpleAttributeSet blueAttr;
    private static SimpleAttributeSet yellowAttr;
    private static SimpleAttributeSet grayAttr;


    private ColoStyles() {
        // 红色文字样式
        redAttr = getRedAttr();

        // 默认黑色文字样式
        blackAttr = getBlackAttr();

        // 蓝色文字样式 - 强调信息
        blueAttr = getBlueAttr();

        // 绿色文字样式 - 成功/存在
        greenAttr = getGreenAttr();
        yellowAttr = getYellowAttr();
        grayAttr = getGrayAttr();
    }


    // 获取红色文本样式（单例）
    public static SimpleAttributeSet getRedAttr() {
        if (redAttr == null) {
            redAttr = new SimpleAttributeSet();
            StyleConstants.setForeground(redAttr, Color.RED);
        }
        return redAttr;
    }

    // 获取黑色文本样式（单例）
    public static SimpleAttributeSet getBlackAttr() {
        if (blackAttr == null) {
            blackAttr = new SimpleAttributeSet();
            StyleConstants.setForeground(blackAttr, Color.BLACK);
        }
        return blackAttr;
    }

    // 获取蓝色文本样式（单例）
    public static SimpleAttributeSet getBlueAttr() {
        if (blueAttr == null) {
            blueAttr = new SimpleAttributeSet();
            StyleConstants.setForeground(blueAttr, Color.BLUE);
            StyleConstants.setBold(blueAttr, true);
        }
        return blueAttr;
    }

    // 获取绿色文本样式（单例）
    public static SimpleAttributeSet getGreenAttr() {
        if (greenAttr == null) {
            greenAttr = new SimpleAttributeSet();
            StyleConstants.setForeground(greenAttr, new Color(0, 128, 0)); // 深绿色
        }
        return greenAttr;
    }
    public static SimpleAttributeSet getYellowAttr() {
        if (yellowAttr == null) {
            yellowAttr = new SimpleAttributeSet();
            StyleConstants.setForeground(yellowAttr, Color.YELLOW);
        }
        return yellowAttr;
    }
    public static SimpleAttributeSet getGrayAttr() {
        if (grayAttr == null) {
            grayAttr = new SimpleAttributeSet();
            StyleConstants.setForeground(grayAttr, Color.GRAY);
        }
        return grayAttr;
    }
}
